.or_insert_with(HashSet::new)
.extend(output.cfgs.iter().cloned());
+ cx.compilation.extra_env.entry(pkg.clone())
+ .or_insert_with(Vec::new)
+ .extend(output.env.iter().cloned());
+
for dir in output.library_paths.iter() {
cx.compilation.native_dirs.insert(dir.clone());
}
let filenames = cx.target_filenames(unit)?;
let root = cx.out_dir(unit);
+ let kind = unit.kind;
// Prepare the native lib state (extra -L and -l flags)
let build_state = cx.build_state.clone();
pass_l_flag, ¤t_id)?;
add_plugin_deps(&mut rustc, &build_state, &build_deps,
&root_output)?;
- add_custom_env(&mut rustc, &build_state, &build_deps, ¤t_id)?;
+ add_custom_env(&mut rustc, &build_state, ¤t_id, kind)?;
}
// FIXME(rust-lang/rust#18913): we probably shouldn't have to do
// been put there by one of the `build_scripts`) to the command provided.
fn add_custom_env(rustc: &mut ProcessBuilder,
build_state: &BuildMap,
- _: &BuildScripts,
- current_id: &PackageId) -> CargoResult<()> {
- let key = (current_id.clone(), Kind::Host);
+ current_id: &PackageId,
+ kind: Kind) -> CargoResult<()> {
+ let key = (current_id.clone(), kind);
if let Some(output) = build_state.get(&key) {
for &(ref name, ref value) in output.env.iter() {
rustc.env(name, value);
for cfg in output.cfgs.iter() {
rustdoc.arg("--cfg").arg(cfg);
}
+ for &(ref name, ref value) in output.env.iter() {
+ rustdoc.env(name, value);
+ }
}
state.running(&rustdoc);
rustdoc.exec().chain_error(|| {
#[test]
fn env_build() {
- let build = project("builder")
+ let p = project("foo")
.file("Cargo.toml", r#"
[package]
- name = "builder"
+ name = "foo"
version = "0.0.1"
authors = []
build = "build.rs"
println!("cargo:rustc-env=FOO=foo");
}
"#);
- assert_that(build.cargo_process("build").arg("-v"),
+ assert_that(p.cargo_process("build").arg("-v"),
execs().with_status(0));
- assert_that(build.cargo("run").arg("-v"),
+ assert_that(p.cargo("run").arg("-v"),
execs().with_status(0).with_stdout("foo\n"));
}
[COMPILING] foo v0.0.1 ({dir})
[RUNNING] [..] build.rs [..]
[RUNNING] `[..][/]build-script-build`
-[RUNNING] [..] --cfg foo[..]
-[RUNNING] [..] --cfg foo[..]
-[RUNNING] [..] --cfg foo[..]
+[RUNNING] [..] --crate-name foo[..]
+[RUNNING] [..] --crate-name foo[..]
+[RUNNING] [..] --crate-name test[..]
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
[RUNNING] `[..][/]foo-[..][EXE]`
[RUNNING] `[..][/]test-[..][EXE]`
[DOCTEST] foo
-[RUNNING] [..] --cfg foo[..]", dir = p.url()))
+[RUNNING] [..] --crate-name foo[..]", dir = p.url()))
.with_stdout("
running 0 tests
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
+
+running 0 tests
+
+test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
+
"));
}
+#[test]
+fn env_doc() {
+ let p = project("foo")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+ build = "build.rs"
+ "#)
+ .file("src/main.rs", r#"
+ const FOO: &'static str = env!("FOO");
+ fn main() {}
+ "#)
+ .file("build.rs", r#"
+ fn main() {
+ println!("cargo:rustc-env=FOO=foo");
+ }
+ "#);
+ assert_that(p.cargo_process("doc").arg("-v"),
+ execs().with_status(0));
+}
+
#[test]
fn flags_go_into_tests() {
let p = project("foo")